package com.ljcalc.business.components.fetchers;

import java.util.LinkedList;
import java.util.List;

import org.apache.xerces.xni.XMLString;

import com.ljcalc.business.components.Combination;
import com.ljcalc.business.components.SaxHandler;

public class HistoryResultItemListHandler extends SaxHandler {

	protected boolean startRecording = false;
	protected List<Combination> list = null;
	protected Combination comb = null;
	
	public HistoryResultItemListHandler() {
		list = null;
		startRecording = false;
	}
	
	protected List<Combination> extract(List<Combination> thelist, Combination thecomb, XMLString text) {
		if(thelist==null){
			thelist = new LinkedList<Combination>();
		}    

		String resultCom = text.toString();
		int strHead = 0;
		for(int i=0;i<resultCom.length();i++){
			if(Character.isWhitespace(resultCom.charAt(i))||Character.isSpaceChar(resultCom.charAt(i))){
				if(strHead<i){
					thecomb.insertNumber(Long.parseLong((String) resultCom.substring(strHead, i)));
					strHead=i+1;
				}else{
					strHead++;
				}
			}
			
			if(i==resultCom.length()-1&&strHead<=i){
				thecomb.insertNumber(Long.parseLong((String) resultCom.substring(strHead, resultCom.length())));
			}
		}
		if(!thelist.contains(thecomb)){
			thelist.add(thecomb);
		}
		
		return thelist;
	}
	
	public LinkedList<Combination> getList() {
		// TODO Auto-generated method stub
		return (LinkedList<Combination>) list;
	}
}
